<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>垃圾箱</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <script type="text/javascript" src="../../js/jquery-3.2.1.js"></script>
    <script type="text/javascript" src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="../welcome.html">首页</a>
        <a href="member-remove.html">垃圾箱</a>
      </span>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so"  method="post" >
          <input type="text" id="keyword" name="keyword"  placeholder="搜索" autocomplete="off" class="layui-input">
          <button class="layui-btn" id="NewsSearch" ><i class="layui-icon">&#xe615;</i></button>
      		<a class="layui-btn layui-btn-small" style="line-height:2.5em;" href="javascript:location.replace(location.href);" title="刷新">
        		<i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </form>
      </div>
        <span class="x-right" style="line-height:40px">共有数据：<span id="listnum"></span>条</span>
      <table class="layui-table">
        <thead>
          <tr>
            <th>账号</th>
            <th>姓名</th>
            <th>账号类型</th>
            <th >操作</th>
            </tr>
        </thead>
        <tbody id="showremove">
          
        </tbody>
      </table>
      <div class="layui-table" id="page">
        
      </div>

    </div>
	<script>
        
        layui.use(['laytpl','laypage','form'], function(){
        	
        	var laypage = layui.laypage;
            var form = layui.form;
            var laydate = layui.laydate;

            //第一次页面加载执行查询所有数据
        	$(function(){
        		showRemove();
        	});
        	
        	//按照条件查询的表单提交
        	form.on("submit()",function(data){
        		
        	    var keyword = $("#keyword").val();
        	    var jsondata={};
            	if(keyword!=""){
            		jsondata.keyword=keyword;
            	};
        	    
            	showRemove(jsondata);
        		return false;
        	});
        	
        	
        	

        //渲染，分页的函数
        function showRemove(jsondata){
        	
        	console.log(jsondata);
        	
     	   $.ajax({
 	    		type: "post",
 	    		url: "../../admin/showRemove",
 	    		async: true,
 	    		data:jsondata,
 	    		dataType:'json',
 	    		success: function(map) {
 	    	//		var arrId = [];//装id
 	    			document.getElementById("listnum").innerHTML=map.size;
 	    			
 	    			//分页
 	    			laypage.render({
 	    	    	    elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
 	    	    	    ,count: map.size //数据总数，从服务端得到
 	    	    	    ,limit: 10
 	    	    	    ,skip: true //开启跳页
 	    	    	    ,jump: function(obj, first){
 	    	    	    	      //模拟渲染
 	    	    	    	      document.getElementById("showremove").innerHTML = function(){
 	    	    	    	    	
 	    	    	    	        var arr = []
 	    	    	    	        ,thisData = map.listRemove.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
 	    	    	    	        layui.each(thisData, function(index, item){
 	    	    	    	        	//前端数据显示的调整
 	    	    	    	        	if(item.personName==null||item.personName==""){
											item.presonName="";
										}
 	    	    	    	        	if(item.isAdmin==1){
											item.isAdmin="管理员";
										}
 	    	    	    	        	if(item.isAdmin==2){
											item.isAdmin="普通业主";
										}
										//数据模板的渲染
 	    	    	    	        	var getTpl = document.getElementById("tpl").innerHTML;
 	    	    	    	        	arr.push(layui.laytpl(getTpl).render(item));
 	    	    	    	        });
 	    	    	    	         return arr.join(''); 
 	    	    	    	      }();
 	    	    	    	    

 	    			

 	    		
 	    			        //为删除单个数据项功能的事件绑定
 	    			        $(".del").bind("click",function(){
 	    			        	
 	    			        	 var id = this.parentNode.parentNode.getAttribute("data-id");
 	    			    	     var userType = this.parentNode.getAttribute("data-id");
 	    			        	
 	    			        	 layer.confirm("删除后,该账户将无法恢复,是否继续?",function(){
 	    			        		 
	 	 	    			    	  var isAdmin;
	 	 	    			    	  if(userType=='管理员'){
	 	 	    			    		  isAdmin=1;
	 	 	    			    	  }
	 	 	    			    	  if(userType=="普通业主"){
	 	 	    			    		  isAdmin=2;
	 	 	    			    	  }
	 	 	    			    	  
	 		 	    			    	 $.ajax({
	 		                                 type:"post",
	 		                                 url:"../../admin/permanentDelete",
	 		                                 async:true,
	 		                                 data:{
	 		                                	 "AccID":id,
	 		                                	 "isAdmin":isAdmin
	 		                                 },
	 		                                 success:function(result){
	 		                                	 if(result.msg=="success"){
	 		                                		 layer.msg('已永久删除账号!',{icon:1,time:1500});
	 		                                	 }else{
	 		                                		 layer.msg('删除失败!',{icon:5,time:1500},function(){
	 		                                			location.reload();
	 		                                		 });
	 		                                	 }
	 		                                 },
	 		                                 error:function(){
	 		                                	 layer.msg("数据异常", {icon: 2,time:1500});
	 		                                 }
	 		                              });
 	    			        	 });
                             });
 	    			        
 	    			        //为修改数据项功能的事件绑定
 	    			       $(".recovery").bind("click",function(){
 	    			    	  
 	    			    	  var id = this.parentNode.parentNode.getAttribute("data-id");
 	    			    	  var userType = this.parentNode.getAttribute("data-id");
 	    			    	  var isAdmin;
 	    			    	  if(userType=='管理员'){
 	    			    		  isAdmin=1;
 	    			    	  }
 	    			    	  if(userType=="普通业主"){
 	    			    		  isAdmin=2;
 	    			    	  }
 	    			    	  
	 	    			    	 $.ajax({
	                                 type:"post",
	                                 url:"../../admin/recoveryAcc",
	                                 async:true,
	                                 data:{
	                                	 "AccID":id,
	                                	 "isAdmin":isAdmin
	                                 },
	                                 success:function(result){
	                                	 if(result.msg=="success"){
	                                		 layer.msg('已恢复账号的使用!',{icon:1,time:1500},function(){
	                                			 location.reload();
	                                		 });
	                                	 }else{
	                                		 layer.msg('恢复账号失败!',{icon:5,time:1500});
	                                	 }
	                                 },
	                                 error:function(){
	                                	 layer.msg("数据异常", {icon: 2,time:1500});
	                                 }
	                              });
 	    			    	   
 	    			       });
 	    	    	  	 }
	    	    	});
 	    		},
 	    		error: function() {
 	    			layer.alert("数据异常", {icon: 2,time:1500});
 	    		}
 	    	});
        }

  });
    </script>

  </body>
  
  <script id="tpl" type="text/html">
 
    <tr id="tr{{ d.dataID }}" data-id='{{ d.dataID }}'>
    <td>{{ d.personAcc }}</td>
    <td>{{ d.personName }}</td>
    <td>{{ d.isAdmin }}</td>
    <td class="td-manage" data-id='{{ d.isAdmin }}'>
	  <span id="{{ d.isAdmin }}"></span>
      <a title="恢复" class="recovery"  href="javascript:;" >
        <i class="layui-icon">&#xe612;</i>
      </a>
      <a title="永久删除" class="del"  href="javascript:;" >
        <i class="layui-icon">&#x1007;</i>
      </a>
    </td>
  </tr>
    </script>

</html>